home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6936 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news.th-darmstadt.de!news
  2. From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Will it be auto-deleted?
  5. Date: Tue, 20 Feb 1996 16:01:08 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Message-ID: <3129E234.1C06089B@intellektik.informatik.th-darmstadt.de>
  8. References: <1996Feb20.110314.46035@yogi.urz.unibas.ch>
  9. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; SunOS 4.1.3 sun4m)
  14.  
  15. Song Jin wrote:
  16. > I have a question:
  17. > void myfunction(void)
  18. > {
  19. >  double *mypointer = new double[100];
  20. >  .....
  21. > }
  22. > The mypointer and the buffer it pointed will be auto-deleted after returned
  23. > from myfunction, am I right?
  24.  
  25. No -- only the memory for the pointer is released.
  26. Thus you have to destroy the array via 'delete[] mypointer'.
  27. However if you declare the array as auto-variable residing
  28. on the stack, e.g.:
  29.  
  30.            double mypointer[100];
  31.  
  32. the appropriate memory will be released automatically at the
  33. end of the function.
  34.  
  35.     Enno
  36.